﻿using System.Collections.Generic;

namespace N2.Workflow
{
	using Items;
	
	/// <summary>
	/// Complete information needed to perform a workflow action
	/// with IWorkflowProvider.PerformAction(..) method.
	/// </summary>
	class ActionArguments
	{
		#region Fields
		
		internal readonly ExecutionMode Mode;

		#endregion Fields

		#region Constructors

		ActionArguments(ExecutionMode mode)
		{
			this.Mode = mode;
		}

		#endregion Constructors

		#region Properties

		/// <summary>
		/// Symblic name of the action,
		/// allowed for the current item's state.
		/// </summary>
		internal string ActionName { get; set; }
		
		/// <summary>
		/// Already filled information about the future item state.
		/// If it's happen to be a real ContentItem, than it's get
		/// persisted as item's state. Otherwise, new state item gets created
		/// and values are copied from this item.
		/// </summary>
		internal IItemState State { get; set; }

		/// <summary>
		/// Property bag to fill the future item's state
		/// </summary>
		internal object Values { get; private set; }

		internal IActionDefinition Action { get; set; }

		internal ItemState ItemStateCandidate { get; set; }

		#endregion Properties

		#region Static Methods

		public static ActionArguments ByName(string name, object values)
		{
			return new ActionArguments(ExecutionMode.ByName) {
				ItemStateCandidate = values as ItemState,
				ActionName = name,
				Values = values,
			};
		}
		
		public static ActionArguments ByState(IItemState newState)
		{
			return new ActionArguments(ExecutionMode.ByState) {
				ItemStateCandidate = newState as ItemState,
				Action = newState.Action,
				State = newState,
			};
		}

		#endregion Static Methods

		#region Types

		internal enum ExecutionMode
		{
			ByName,
			ByState
		}

		#endregion Types
	}
}
